package com.ruoyi.quartz.task;

import com.ruoyi.distributionPoster.service.IDistributionPosterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 分销海报清理定时任务
 * 定期清理过期的二维码数据，防止数据库积累过多无用数据
 */
@Component("distributionPosterCleanupTask")
public class DistributionPosterCleanupTask {

    private static final Logger log = LoggerFactory.getLogger(DistributionPosterCleanupTask.class);

    @Autowired
    private IDistributionPosterService distributionPosterService;

    /**
     * 执行分销海报清理任务
     * 每天凌晨2点执行，清理过期超过30天的二维码数据
     */
    public void execute() {
        try {
            log.info("开始执行分销海报清理任务");

            String result = distributionPosterService.cleanExpiredDistributionPosters();

            log.info("分销海报清理任务执行完成: {}", result);

        } catch (Exception e) {
            log.error("分销海报清理任务执行失败", e);
        }
    }

    /**
     * 手动触发清理任务（用于测试或紧急清理）
     */
    public void cleanNow() {
        log.info("手动触发分销海报清理任务");
        execute();
    }
}